<dt>Micheal Muré</dd>
<dd>portability fixes</dd>
+ <dt>Edward E</dt>
+ <dd>win32 platform adaptations</dd>
+
<dt>Maxime Nicco</dt>
<dl>HSV color model extension</dl>
<dt>Teo Mazars</dt>
-babl 0.1.22
+babl 0.1.24
Dynamic; any to any, pixel format conversion library.
installation (or a variation on this theme):
------------------------------------------------------------
- foo$ wget ftp://ftp.gtk.org/pub/babl/0.1/babl-0.1.22.tar.bz2
- foo$ tar jxf babl-0.1.22.tar.gz
- foo$ cd babl-0.1.22
- foo/babl-0.1.22$ ./configure && make && sudo make install
+ foo$ wget ftp://ftp.gtk.org/pub/babl/0.1/babl-0.1.24.tar.bz2
+ foo$ tar jxf babl-0.1.24.tar.gz
+ foo$ cd babl-0.1.24
+ foo/babl-0.1.24$ ./configure && make && sudo make install
------------------------------------------------------------
am__DIST_COMMON = $(srcdir)/INSTALL.in $(srcdir)/Makefile.in \
$(srcdir)/babl.pc.in $(srcdir)/config.h.in AUTHORS COPYING \
INSTALL NEWS README TODO compile config.guess config.sub \
- depcomp install-sh ltmain.sh missing
+ install-sh ltmain.sh missing
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
-->
+
+2017-02-01 babl-0.1.24 </dt><dd>
+Improvements to profile cache persistance, fast paths that improve actual GIMP
+use on various precisions, use single precision constants for some more of CIE
+computions.
+ </dd><dt>
2016-11-05 babl-0.1.22 </dt><dd>
Added cache of profiled conversions, added HCY color model, some precision and
performance updated for fast paths.
-Babl-0.1.22
+Babl-0.1.24
Contents
Download
-The latest versioned development version of babl can be found in ftp://
-ftp.gtk.org/pub/babl/.
+The latest versioned development version of babl can be found in https:
+//download.gimp.org/pub/babl/.
Babl uses git. The main repository is hosted by GNOME. It can be
browsed online and cloned with:
release is done a babl release is most often put out just prior to the
GEGL release.
+2017-02-01 babl-0.1.24
+ Improvements to profile cache persistance, fast paths that improve
+ actual GIMP use on various precisions, use single precision
+ constants for some more of CIE computions.
2016-11-05 babl-0.1.22
Added cache of profiled conversions, added HCY color model, some
precision and performance updated for fast paths.
cleanups
Micheal Muré
portability fixes
+Edward E
+ win32 platform adaptations
Maxime Nicco
HSV color model extension
Massimo Valentini
stability fixes
-/babl-0.1.22
+/babl-0.1.24
* <http://www.gnu.org/licenses/>.
*/
+#ifdef _WIN32
+#include <shlobj.h>
+#endif
+
#include <time.h>
#include <sys/stat.h>
#include "config.h"
}
}
}
- return -1;
+ return 0;
}
static int
if (getenv ("HOME"))
sprintf (path, "%s/.cache/babl/babl-fishes", getenv("HOME"));
#else
- if (getenv ("TEMP"))
+{
+ char win32path[4096];
+ if (SHGetFolderPathA (NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, win32path) == S_OK)
+ sprintf (path, "%s\\%s\\babl-fishes.txt", win32path, BABL_LIBRARY);
+ else if (getenv ("TEMP"))
sprintf (path, "%s\\babl-fishes.txt", getenv("TEMP"));
+}
#endif
if (stat (path, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
((*fb)->fish.processings - (*fa)->fish.processings);
}
+static const char *cache_header (void)
+{
+ static char buf[2048];
+ if (strchr (BABL_GIT_VERSION, ' ')) // we must be building from tarball
+ sprintf (buf, "#%i.%i.%i BABL_PATH_LENGTH=%d BABL_TOLERANCE=%f",
+ BABL_MAJOR_VERSION, BABL_MINOR_VERSION, BABL_MICRO_VERSION,
+ _babl_max_path_len (), _babl_legal_error ());
+ else
+ sprintf (buf, "#%s BABL_PATH_LENGTH=%d BABL_TOLERANCE=%f",
+ BABL_GIT_VERSION,
+ _babl_max_path_len (), _babl_legal_error ());
+ return buf;
+}
+
void babl_store_db (void)
{
BablDb *db = babl_fish_db ();
int i;
- FILE *dbfile = fopen (fish_cache_path (), "w");
+ char *tmpp = calloc(8000,1);
+ FILE *dbfile;
+
+ sprintf (tmpp, "%s~", fish_cache_path ());
+ dbfile = fopen (tmpp, "w");
if (!dbfile)
return;
- fprintf (dbfile, "#%s BABL_PATH_LENGTH=%d BABL_TOLERANCE=%f\n",
- BABL_GIT_VERSION, _babl_max_path_len (), _babl_legal_error ());
+ fprintf (dbfile, "%s\n", cache_header ());
/* sort the list of fishes by usage, making next run more efficient -
* and the data easier to approach as data for targeted optimization
fprintf (dbfile, "%s----\n", tmp);
}
fclose (dbfile);
+
+ rename (tmpp, fish_cache_path());
+ free (tmpp);
}
static int
case '#':
/* if babl has changed in git .. drop whole cache */
{
- char buf[2048];
- sprintf (buf, "#%s BABL_PATH_LENGTH=%d BABL_TOLERANCE=%f",
- BABL_GIT_VERSION, _babl_max_path_len (), _babl_legal_error ());
- if (strcmp ( token, buf))
+ if (strcmp ( token, cache_header ()))
{
free (contents);
return;
#include "babl-internal.h"
#include "babl-ref-pixels.h"
-#define BABL_TOLERANCE 0.000006
+#define BABL_TOLERANCE 0.000001
#define BABL_MAX_COST_VALUE 2000000
#define BABL_HARD_MAX_PATH_LENGTH 8
#define BABL_MAX_NAME_LEN 1024
get_conversion_path (&pc, (Babl *) source, 0, max_path_length ());
+ /* second attempt,. at path length + 1*/
+ if (babl->fish_path.conversion_list->count == 0 &&
+ max_path_length () + 1 <= BABL_HARD_MAX_PATH_LENGTH)
+ get_conversion_path (&pc, (Babl *) source, 0, max_path_length () + 1);
+
babl_in_fish_path--;
babl_free (pc.current_path);
}
{
babl_free (babl);
babl_mutex_unlock (babl_format_mutex);
+
+#ifndef BABL_UNSTABLE
+ if (debug_conversions)
+#endif
+ {
+ static int warnings = 0;
+ if (warnings++ == 0)
+ fprintf (stderr,
+"Missing fast-path babl conversion detected, Implementing missing babl fast paths\n"
+"accelerates GEGL, GIMP and other software using babl, warnings are printed on\n"
+"first occurance of formats used where a conversion has to be synthesized\n"
+"programmatically by babl based on format description\n"
+"\n");
+
+ fprintf (stderr, "*WARNING*: missing babl fast path(s) between formats \"%s\" and \"%s\"\n",
+ babl_get_name (source),
+ babl_get_name (destination));
+
+ }
return NULL;
}
* source/destination values. */
ptrdiff_t id = source - destination;
/* instances with id 0 won't be inserted into database */
+ id *= ((((size_t) (source))) % 37);
+
if (id == 0)
id = 1;
return id;
int id)
{
int hash = 0;
- int i;
-
- for (i = 0; i < sizeof (int); i++)
- {
- hash += id & 0xFF;
- hash += (hash << 10);
- hash ^= (hash >> 6);
- id >>= 8;
- }
+ hash += id & 0xFF;
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
+ id >>= 8;
+ hash += id & 0xFF;
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
#define BABL_MAJOR_VERSION 0
#define BABL_MINOR_VERSION 1
-#define BABL_MICRO_VERSION 22
+#define BABL_MICRO_VERSION 24
/** Get the version information on the babl library */
void babl_get_version (int *major,
return x*y;
}
+
+#include <stdint.h>
+/* frexpf copied from musl */
+static inline float babl_frexpf(float x, int *e)
+{
+ union { float f; uint32_t i; } y = { x };
+ int ee = y.i>>23 & 0xff;
+
+ if (!ee) {
+ if (x) {
+ x = babl_frexpf(x*0x1p64, e);
+ *e -= 64;
+ } else *e = 0;
+ return x;
+ } else if (ee == 0xff) {
+ return x;
+ }
+
+ *e = ee - 0x7e;
+ y.i &= 0x807ffffful;
+ y.i |= 0x3f000000ul;
+ return y.f;
+}
+
+
//////////////////////////////////////////////
/* a^b = exp(b*log(a))
*
init_newtonf (float x, float exponent, float c0, float c1, float c2)
{
int iexp;
- float y = frexpf(x, &iexp);
+ float y = babl_frexpf(x, &iexp);
y = 2*y+(iexp-2);
c1 *= M_LN2*exponent;
c2 *= M_LN2*M_LN2*exponent*exponent;
#else
#define linear_to_gamma_2_2(value) (pow((value), (1.0F/2.2F)))
#define gamma_2_2_to_linear(value) (pow((value), 2.2F))
+
+ #define babl_linear_to_gamma_2_2f(value) (powf((value), (1.0f/2.2f)))
+ #define babl_gamma_2_2_to_linearf(value) (powf((value), 2.2f))
#endif
# Attempt to guess a canonical system name.
# Copyright 1992-2016 Free Software Foundation, Inc.
-timestamp='2016-04-02'
+timestamp='2016-10-02'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
*) machine=${UNAME_MACHINE_ARCH}-unknown ;;
esac
# The Operating System including object format, if it has switched
- # to ELF recently, or will in the future.
+ # to ELF recently (or will in the future) and ABI.
case "${UNAME_MACHINE_ARCH}" in
- arm*|earm*|i386|m68k|ns32k|sh3*|sparc|vax)
+ earm*)
+ os=netbsdelf
+ ;;
+ arm*|i386|m68k|ns32k|sh3*|sparc|vax)
eval $set_cc_for_build
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ELF__
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
;;
+ mips64el:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
openrisc*:Linux:*:*)
echo or1k-unknown-linux-${LIBC}
exit ;;
ppcle:Linux:*:*)
echo powerpcle-unknown-linux-${LIBC}
exit ;;
+ riscv32:Linux:*:* | riscv64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
s390:Linux:*:* | s390x:Linux:*:*)
echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
exit ;;
cat >&2 <<EOF
$0: unable to guess system type
-This script, last modified $timestamp, has failed to recognize
-the operating system you are using. It is advised that you
-download the most up to date version of the config scripts from
+This script (version $timestamp), has failed to recognize the
+operating system you are using. If your script is old, overwrite
+config.guess and config.sub with the latest versions from:
http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
and
http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
-If the version you run ($0) is already up to date, please
-send the following data and any information you think might be
-pertinent to <config-patches@gnu.org> in order to provide the needed
-information to handle your system.
+If $0 has already been updated, send the following data and any
+information you think might be pertinent to config-patches@gnu.org to
+provide the necessary information to handle your system.
config.guess timestamp = $timestamp
# Configuration validation subroutine script.
# Copyright 1992-2016 Free Software Foundation, Inc.
-timestamp='2016-03-30'
+timestamp='2016-11-04'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
- kopensolaris*-gnu* | \
+ kopensolaris*-gnu* | cloudabi*-eabi* | \
storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
| open8 | or1k | or1knd | or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle \
+ | pru \
| pyramid \
| riscv32 | riscv64 \
| rl78 | rx \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+ | pru-* \
| pyramid-* \
| riscv32-* | riscv64-* \
| rl78-* | romp-* | rs6000-* | rx-* \
basic_machine=m68k-bull
os=-sysv3
;;
+ e500v[12])
+ basic_machine=powerpc-unknown
+ os=$os"spe"
+ ;;
+ e500v[12]-*)
+ basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=$os"spe"
+ ;;
ebmon29k)
basic_machine=a29k-amd
os=-ebmon
ppc-* | ppcbe-*)
basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
- ppcle | powerpclittle | ppc-le | powerpc-little)
+ ppcle | powerpclittle)
basic_machine=powerpcle-unknown
;;
ppcle-* | powerpclittle-*)
;;
ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
- ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+ ppc64le | powerpc64little)
basic_machine=powerpc64le-unknown
;;
ppc64le-* | powerpc64little-*)
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* | -cegcc* \
| -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
- | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+ | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
| -linux-newlib* | -linux-musl* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
| -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
- | -onefs* | -tirtos*)
+ | -onefs* | -tirtos* | -phoenix* | -fuchsia*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for babl 0.1.22.
+# Generated by GNU Autoconf 2.69 for babl 0.1.24.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
# Identity of this package.
PACKAGE_NAME='babl'
PACKAGE_TARNAME='babl'
-PACKAGE_VERSION='0.1.22'
-PACKAGE_STRING='babl 0.1.22'
+PACKAGE_VERSION='0.1.24'
+PACKAGE_STRING='babl 0.1.24'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures babl 0.1.22 to adapt to many kinds of systems.
+\`configure' configures babl 0.1.24 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of babl 0.1.22:";;
+ short | recursive ) echo "Configuration of babl 0.1.24:";;
esac
cat <<\_ACEOF
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-babl configure 0.1.22
+babl configure 0.1.24
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by babl $as_me 0.1.22, which was
+It was created by babl $as_me 0.1.24, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
BABL_MAJOR_VERSION=0
BABL_MINOR_VERSION=1
-BABL_MICRO_VERSION=22
+BABL_MICRO_VERSION=24
BABL_INTERFACE_AGE=1
-BABL_BINARY_AGE=122
-BABL_VERSION=0.1.22
-BABL_REAL_VERSION=0.1.22
+BABL_BINARY_AGE=124
+BABL_VERSION=0.1.24
+BABL_REAL_VERSION=0.1.24
BABL_API_VERSION=0.1
-BABL_LIBRARY_VERSION="121:1:121"
+BABL_LIBRARY_VERSION="123:1:123"
BABL_CURRENT_MINUS_AGE=0
# Define the identity of the package.
PACKAGE='babl'
- VERSION='0.1.22'
+ VERSION='0.1.24'
# Some tools Automake needs.
int
main ()
{
-__m128 val = _mm_cvtph_ps ((__m128i)_mm_setzero_ps());
+__m128 val = _mm_cvtph_ps ((__m128i)_mm_setzero_ps()); __m128i val2 = _mm_insert_epi64((__m128i)_mm_setzero_ps(), 0, 0);
;
return 0;
}
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by babl $as_me 0.1.22, which was
+This file was extended by babl $as_me 0.1.24, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-babl config.status 0.1.22
+babl config.status 0.1.24
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
m4_define([babl_major_version], [0])
m4_define([babl_minor_version], [1])
-m4_define([babl_micro_version], [22])
+m4_define([babl_micro_version], [24])
m4_define([babl_real_version],
[babl_major_version.babl_minor_version.babl_micro_version])
m4_define([babl_version], [babl_real_version])
CFLAGS="$CFLAGS $sse_flag $f16c_flag"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <immintrin.h>],[__m128 val = _mm_cvtph_ps ((__m128i)_mm_setzero_ps());])],
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <immintrin.h>],[__m128 val = _mm_cvtph_ps ((__m128i)_mm_setzero_ps()); __m128i val2 = _mm_insert_epi64((__m128i)_mm_setzero_ps(), 0, 0);])],
AC_DEFINE(USE_F16C, 1, [Define to 1 if f16c intrinsics are available.])
AC_MSG_RESULT(yes)
,
<h2>Download</h2>
<p>The latest versioned development version of babl can be found in
- <a href='ftp://ftp.gtk.org/pub/babl/'>ftp://ftp.gtk.org/pub/babl/</a>.
+ <a href='https://download.gimp.org/pub/babl/'>https://download.gimp.org/pub/babl/</a>.
</p>
<p>Babl uses git. The main repository is hosted by GNOME.
--- /dev/null
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2016, Ă˜yvind KolĂ¥s.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <stdint.h>
+
+#include "babl.h"
+
+#include "base/util.h"
+#include "extensions/util.h"
+
+static inline long
+conv_rgbu16_rgbau16 (unsigned char *src,
+ unsigned char *dst,
+ long samples)
+
+
+{
+ uint16_t *src16 = (uint16_t*) src;
+ uint16_t *dst16 = (uint16_t*) dst;
+ long n = samples;
+
+ while (n--)
+ {
+ *dst16++ = *src16++;
+ *dst16++ = *src16++;
+ *dst16++ = *src16++;
+ *dst16++ = 0xffff;
+ }
+
+ return samples;
+}
+
+static inline long
+conv_yu16_yau16 (unsigned char *src,
+ unsigned char *dst,
+ long samples)
+
+
+{
+ uint16_t *src16 = (uint16_t*) src;
+ uint16_t *dst16 = (uint16_t*) dst;
+ long n = samples;
+
+ while (n--)
+ {
+ *dst16++ = *src16++;
+ *dst16++ = 0xffff;
+ }
+
+ return samples;
+}
+
+int init (void);
+
+int
+init (void)
+{
+ babl_conversion_new (
+ babl_format ("R'G'B' u16"),
+ babl_format ("R'G'B'A u16"),
+ "linear",
+ conv_rgbu16_rgbau16,
+ NULL);
+
+ babl_conversion_new (
+ babl_format ("Y' u16"),
+ babl_format ("Y'A u16"),
+ "linear",
+ conv_yu16_yau16,
+ NULL);
+
+ babl_conversion_new (
+ babl_format ("RGB u16"),
+ babl_format ("RGBA u16"),
+ "linear",
+ conv_rgbu16_rgbau16,
+ NULL);
+
+ babl_conversion_new (
+ babl_format ("Y u16"),
+ babl_format ("YA u16"),
+ "linear",
+ conv_yu16_yau16,
+ NULL);
+ return 0;
+}
#define DEGREES_PER_RADIAN (180 / 3.14159265358979323846)
#define RADIANS_PER_DEGREE (1 / DEGREES_PER_RADIAN)
-#define LAB_EPSILON (216.0 / 24389.0)
-#define LAB_KAPPA (24389.0 / 27.0)
+#define LAB_EPSILON (216.0f / 24389.0f)
+#define LAB_KAPPA (24389.0f / 27.0f)
/* The constants below hard-code the D50-adapted sRGB ICC profile
* reference white, aka the ICC profile D50 illuminant.
* hard-coded D50 ICC profile illuminant values:
*/
-#define D50_WHITE_REF_X 0.964202880
-#define D50_WHITE_REF_Y 1.000000000
-#define D50_WHITE_REF_Z 0.824905400
+#define D50_WHITE_REF_X 0.964202880f
+#define D50_WHITE_REF_Y 1.000000000f
+#define D50_WHITE_REF_Z 0.824905400f
int init (void);
return f * f * f;
}
+/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtf.c */
+/*
+ * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
+ * Debugged and optimized by Bruce D. Evans.
+ */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+/* _cbrtf(x)
+ * Return cube root of x
+ */
+
+#include <math.h>
+#include <stdint.h>
+
+static const unsigned
+B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */
+B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
+
+static inline float _cbrtf(float x)
+{
+ float r,T;
+ union {float f; uint32_t i;} u = {x};
+ uint32_t hx = u.i & 0x7fffffff;
+
+ if (hx >= 0x7f800000) /* cbrt(NaN,INF) is itself */
+ return x + x;
+
+ /* rough cbrt to 5 bits */
+ if (hx < 0x00800000) { /* zero or subnormal? */
+ if (hx == 0)
+ return x; /* cbrt(+-0) is itself */
+ u.f = x*0x1p24f;
+ hx = u.i & 0x7fffffff;
+ hx = hx/3 + B2;
+ } else
+ hx = hx/3 + B1;
+ u.i &= 0x80000000;
+ u.i |= hx;
+
+ T = u.f;
+ r = T*T*T;
+ T = T*((float)x+x+r)/(x+r+r);
+
+ r = T*T*T;
+ T = T*((float)x+x+r)/(x+r+r);
+
+ return T;
+}
+
static long
Yaf_to_Laf (float *src,
float *dst,
{
float yr = src[0];
float a = src[1];
- float L = yr > LAB_EPSILON ? 116.0 * cbrtf (yr) - 16 : LAB_KAPPA * yr;
+ float L = yr > LAB_EPSILON ? 116.0f * _cbrtf (yr) - 16 : LAB_KAPPA * yr;
dst[0] = L;
dst[1] = a;
return samples;
}
+
static long
rgbf_to_Labf (float *src,
float *dst,
float yr = 0.22248840f / D50_WHITE_REF_Y * r + 0.71690369f / D50_WHITE_REF_Y * g + 0.06060791f / D50_WHITE_REF_Y * b;
float zr = 0.01391602f / D50_WHITE_REF_Z * r + 0.09706116f / D50_WHITE_REF_Z * g + 0.71392822f / D50_WHITE_REF_Z * b;
- float fx = xr > LAB_EPSILON ? cbrtf (xr) : (LAB_KAPPA * xr + 16.0f) / 116.0f;
- float fy = yr > LAB_EPSILON ? cbrtf (yr) : (LAB_KAPPA * yr + 16.0f) / 116.0f;
- float fz = zr > LAB_EPSILON ? cbrtf (zr) : (LAB_KAPPA * zr + 16.0f) / 116.0f;
+ float fx = xr > LAB_EPSILON ? _cbrtf (xr) : (LAB_KAPPA * xr + 16.0f) / 116.0f;
+ float fy = yr > LAB_EPSILON ? _cbrtf (yr) : (LAB_KAPPA * yr + 16.0f) / 116.0f;
+ float fz = zr > LAB_EPSILON ? _cbrtf (zr) : (LAB_KAPPA * zr + 16.0f) / 116.0f;
float L = 116.0f * fy - 16.0f;
float A = 500.0f * (fx - fy);
float yr = 0.22248840f / D50_WHITE_REF_Y * r + 0.71690369f / D50_WHITE_REF_Y * g + 0.06060791f / D50_WHITE_REF_Y * b;
float zr = 0.01391602f / D50_WHITE_REF_Z * r + 0.09706116f / D50_WHITE_REF_Z * g + 0.71392822f / D50_WHITE_REF_Z * b;
- float fx = xr > LAB_EPSILON ? cbrtf (xr) : (LAB_KAPPA * xr + 16.0f) / 116.0f;
- float fy = yr > LAB_EPSILON ? cbrtf (yr) : (LAB_KAPPA * yr + 16.0f) / 116.0f;
- float fz = zr > LAB_EPSILON ? cbrtf (zr) : (LAB_KAPPA * zr + 16.0f) / 116.0f;
+ float fx = xr > LAB_EPSILON ? _cbrtf (xr) : (LAB_KAPPA * xr + 16.0f) / 116.0f;
+ float fy = yr > LAB_EPSILON ? _cbrtf (yr) : (LAB_KAPPA * yr + 16.0f) / 116.0f;
+ float fz = zr > LAB_EPSILON ? _cbrtf (zr) : (LAB_KAPPA * zr + 16.0f) / 116.0f;
float L = 116.0f * fy - 16.0f;
float A = 500.0f * (fx - fy);
babl_type_new (
"CIE u16 ab",
- "id", "CIE u8 ab",
"integer",
"unsigned",
"bits", 16,
extdir = $(libdir)/babl-@BABL_API_VERSION@
ext_LTLIBRARIES = \
+ 16bit.la \
cairo.la \
CIE.la \
float-half.la \
}
am__installdirs = "$(DESTDIR)$(extdir)"
LTLIBRARIES = $(ext_LTLIBRARIES)
-CIE_la_LIBADD =
-am_CIE_la_OBJECTS = CIE.lo
-CIE_la_OBJECTS = $(am_CIE_la_OBJECTS)
+16bit_la_LIBADD =
+16bit_la_SOURCES = 16bit.c
+16bit_la_OBJECTS = 16bit.lo
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
+CIE_la_LIBADD =
+am_CIE_la_OBJECTS = CIE.lo
+CIE_la_OBJECTS = $(am_CIE_la_OBJECTS)
HSL_la_LIBADD =
am_HSL_la_OBJECTS = HSL.lo
HSL_la_OBJECTS = $(am_HSL_la_OBJECTS)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
-SOURCES = $(CIE_la_SOURCES) $(HSL_la_SOURCES) $(HSV_la_SOURCES) \
- $(cairo_la_SOURCES) $(fast_float_la_SOURCES) \
+SOURCES = 16bit.c $(CIE_la_SOURCES) $(HSL_la_SOURCES) \
+ $(HSV_la_SOURCES) $(cairo_la_SOURCES) $(fast_float_la_SOURCES) \
$(float_half_la_SOURCES) $(float_la_SOURCES) \
$(gegl_fixups_la_SOURCES) $(gggl_lies_la_SOURCES) \
$(gggl_table_lies_la_SOURCES) $(gggl_table_la_SOURCES) \
$(sse2_int16_la_SOURCES) $(sse2_int8_la_SOURCES) \
$(sse4_int8_la_SOURCES) $(two_table_la_SOURCES) \
$(ycbcr_la_SOURCES)
-DIST_SOURCES = $(CIE_la_SOURCES) $(HSL_la_SOURCES) $(HSV_la_SOURCES) \
- $(cairo_la_SOURCES) $(fast_float_la_SOURCES) \
+DIST_SOURCES = 16bit.c $(CIE_la_SOURCES) $(HSL_la_SOURCES) \
+ $(HSV_la_SOURCES) $(cairo_la_SOURCES) $(fast_float_la_SOURCES) \
$(float_half_la_SOURCES) $(float_la_SOURCES) \
$(gegl_fixups_la_SOURCES) $(gggl_lies_la_SOURCES) \
$(gggl_table_lies_la_SOURCES) $(gggl_table_la_SOURCES) \
extdir = $(libdir)/babl-@BABL_API_VERSION@
ext_LTLIBRARIES = \
+ 16bit.la \
cairo.la \
CIE.la \
float-half.la \
rm -f $${locs}; \
}
+16bit.la: $(16bit_la_OBJECTS) $(16bit_la_DEPENDENCIES) $(EXTRA_16bit_la_DEPENDENCIES)
+ $(AM_V_CCLD)$(LINK) -rpath $(extdir) $(16bit_la_OBJECTS) $(16bit_la_LIBADD) $(LIBS)
+
CIE.la: $(CIE_la_OBJECTS) $(CIE_la_DEPENDENCIES) $(EXTRA_CIE_la_DEPENDENCIES)
$(AM_V_CCLD)$(LINK) -rpath $(extdir) $(CIE_la_OBJECTS) $(CIE_la_LIBADD) $(LIBS)
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/16bit.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CIE.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HSL.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HSV.Plo@am__quote@
conv_rgba8_cairo24_le (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
+ uint32_t *srci = (void *)src;
+ uint32_t *dsti = (void *)dst;
+
while (n--)
{
- unsigned char red = *src++;
- unsigned char green = *src++;
- unsigned char blue = *src++;
- *dst++ = blue;
- *dst++ = green;
- *dst++ = red;
- *dst++ = 255;
- src++;
+ uint32_t orig = *srci++;
+ uint32_t green_alpha = (orig & 0x0000ff00);
+ uint32_t red_blue = (orig & 0x00ff00ff);
+ uint32_t red = red_blue << 16;
+ uint32_t blue = red_blue >> 16;
+ *dsti++ = green_alpha | red | blue | 0xff000000;
}
return samples;
}
*dst++ = 255;
}
return samples;
+
+
}
+#if 0
static inline long
conv_rgbA8_premul_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
{
}
return samples;
}
+#else
+
+static inline long
+conv_rgbA8_premul_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+ uint32_t *srci = (void *)src;
+ uint32_t *dsti = (void *)dst;
+
+ while (n--)
+ {
+ uint32_t orig = *srci++;
+ uint32_t green_alpha = (orig & 0xff00ff00);
+ uint32_t red_blue = (orig & 0x00ff00ff);
+ uint32_t red = red_blue << 16;
+ uint32_t blue = red_blue >> 16;
+ *dsti++ = green_alpha | red | blue;
+ }
+ return samples;
+}
+#endif
+
static inline long
conv_rgbA8_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
*dst++ = div_255 (blue * alpha);
*dst++ = div_255 (green * alpha);
*dst++ = div_255 (red * alpha);
+ *dst++ = alpha;
+ }
+ return samples;
+}
+
+static inline long
+conv_rgb8_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+ while (n--)
+ {
+ unsigned char red = *src++;
+ unsigned char green = *src++;
+ unsigned char blue = *src++;
+
+ *dst++ = blue;
+ *dst++ = green;
+ *dst++ = red;
+ *dst++ = 0xff;
+ }
+ return samples;
+}
+
+
+
+
+static inline long
+conv_yA8_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+ while (n--)
+ {
+ unsigned char gray = *src++;
+ unsigned char alpha = *src++;
+ unsigned char val = div_255 (gray * alpha);
+
#undef div_255
+
+ *dst++ = val;
+ *dst++ = val;
+ *dst++ = val;
*dst++ = alpha;
}
return samples;
}
+static inline long
+conv_yA16_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+ uint16_t *ssrc = (void*) src;
+ while (n--)
+ {
+ float alpha = (ssrc[1]) / 65535.0f;
+ int val = (ssrc[0] * alpha) * (0xff / 65535.0f ) + 0.5f;
+ *dst++ = val;
+ *dst++ = val;
+ *dst++ = val;
+ *dst++ = (alpha * 0xff + 0.5f);
+ ssrc+=2;
+ }
+ return samples;
+}
+
+static inline long
+conv_y8_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+ while (n--)
+ {
+ unsigned char val = *src++;
+ *dst++ = val;
+ *dst++ = val;
+ *dst++ = val;
+ *dst++ = 0xff;
+ }
+ return samples;
+}
+
+static inline long
+conv_y16_cairo32_le (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+ uint16_t *s16 = (void*)src;
+ while (n--)
+ {
+#define div_257(a) ((((a)+128)-(((a)+128)>>8))>>8)
+ uint16_t v16 = *s16++;
+ unsigned char val = div_257(v16);
+#undef dib_257
+ *dst++ = val;
+ *dst++ = val;
+ *dst++ = val;
+ *dst++ = 0xff;
+ }
+ return samples;
+}
+
+static long
+conv_rgbA_gamma_float_cairo32_le (unsigned char *src,
+ unsigned char *dst,
+ long samples)
+{
+ float *fsrc = (float *) src;
+ unsigned char *cdst = (unsigned char *) dst;
+ int n = samples;
+
+ while (n--)
+ {
+ int val = fsrc[2] * 255.0f + 0.5f;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ val = fsrc[1] * 255.0f + 0.5f;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ val = fsrc[0] * 255.0f + 0.5f;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ val = fsrc[3] * 255.0f + 0.5f;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ fsrc+=4;
+ }
+ return samples;
+}
+
static long
conv_rgbafloat_cairo32_le (unsigned char *src,
unsigned char *dst,
return samples;
}
+
+static long
+conv_yafloat_cairo32_le (unsigned char *src,
+ unsigned char *dst,
+ long samples)
+{
+ float *fsrc = (float *) src;
+ unsigned char *cdst = (unsigned char *) dst;
+ int n = samples;
+
+ while (n--)
+ {
+ float gray = *fsrc++;
+ float alpha = *fsrc++;
+ if (alpha >= 1.0)
+ {
+ int val = babl_linear_to_gamma_2_2f (gray) * 0xff + 0.5f;
+ val = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = 0xff;
+ }
+ else if (alpha <= 0.0)
+ {
+ (*(uint32_t*)cdst)=0;
+ cdst+=4;
+ }
+ else
+ {
+ float balpha = alpha * 0xff;
+ int val = babl_linear_to_gamma_2_2f (gray) * balpha + 0.5f;
+ val = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = val;
+ *cdst++ = balpha + 0.5f;
+ }
+ }
+ return samples;
+}
+
int
init (void)
{
babl_component ("PAD"),
NULL
);
-
babl_conversion_new (babl_format ("R'aG'aB'aA u8"), f32, "linear",
conv_rgbA8_premul_cairo32_le, NULL);
+
babl_conversion_new (babl_format ("R'G'B'A u8"), f32, "linear",
conv_rgbA8_cairo32_le, NULL);
+
+ babl_conversion_new (babl_format ("R'G'B' u8"), f32, "linear",
+ conv_rgb8_cairo32_le, NULL);
+
+ babl_conversion_new (babl_format ("Y'A u8"), f32, "linear",
+ conv_yA8_cairo32_le, NULL);
+ babl_conversion_new (babl_format ("Y'A u16"), f32, "linear",
+ conv_yA16_cairo32_le, NULL);
+
+
+ babl_conversion_new (babl_format ("Y' u8"), f32, "linear",
+ conv_y8_cairo32_le, NULL);
+ babl_conversion_new (babl_format ("Y' u16"), f32, "linear",
+ conv_y16_cairo32_le, NULL);
+
babl_conversion_new (babl_format ("RGBA float"), f32, "linear",
conv_rgbafloat_cairo32_le, NULL);
+ babl_conversion_new (babl_format ("YA float"), f32, "linear",
+ conv_yafloat_cairo32_le, NULL);
+
+ babl_conversion_new (babl_format ("R'aG'aB'aA float"), f32, "linear",
+ conv_rgbA_gamma_float_cairo32_le, NULL);
babl_conversion_new (babl_format ("R'G'B'A u8"), f24, "linear",
conv_rgba8_cairo24_le, NULL);
babl_component ("B'"),
NULL
);
+
+ /* formats are registered - but no fast paths, this will be slow */
}
babl_format_new (
"name", "cairo-A8",
return samples;
}
+static INLINE long
+conv_yaF_linear_rgbA8_gamma (unsigned char *src,
+ unsigned char *dst,
+ long samples)
+{
+ float *fsrc = (float *) src;
+ uint8_t *cdst = (uint8_t *) dst;
+ int n = samples;
+
+ while (n--)
+ {
+ float gray = *fsrc++;
+ float alpha = *fsrc++;
+ if (alpha >= 1.0)
+ {
+ int val = linear_to_gamma_2_2_lut (gray) * 0xff + 0.5f;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = 0xff;
+ }
+ else if (alpha <= 0.0)
+ {
+ *((uint32_t*)(cdst))=0;
+ cdst+=4;
+ }
+ else
+ {
+ float balpha = alpha * 0xff;
+ int val = linear_to_gamma_2_2_lut (gray) * balpha + 0.5f;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val;
+ *cdst++ = balpha + 0.5f;
+ }
+ }
+ return samples;
+}
+
+
+
static long
conv_rgbaF_linear_rgbA8_gamma_cairo (unsigned char *src,
unsigned char *dst,
int
init (void)
{
+ const Babl *yaF_linear = babl_format_new (
+ babl_model ("YA"),
+ babl_type ("float"),
+ babl_component ("Y"),
+ babl_component ("A"),
+ NULL);
+
const Babl *rgbaF_linear = babl_format_new (
babl_model ("RGBA"),
babl_type ("float"),
babl_component ("B'"),
NULL);
+ return 0; // XXX: the fast paths registered here doesn't correctly
+ // clamp negative values - disabling for now
{
float f;
float a;
o (rgbaF_gamma, rgbaF_linear);
o (rgbF_linear, rgbF_gamma);
o (rgbF_gamma, rgbF_linear);
-
+ o (yaF_linear, rgbA8_gamma);
return 0;
}
}
#define conv_rgbAF_rgbAD conv_rgbaF_rgbaD
-#define conv_rgbAD_rgbAD conv_rgbaD_rgbaF
+#define conv_rgbAD_rgbAF conv_rgbaD_rgbaF
#define conv_rgbAF_rgbA16 conv_rgbaF_rgba16
#define conv_gF_g16 conv_F_16
#define conv_gAF_gA16 conv_gaF_ga16
return samples;
}
+
+static long
+conv_gF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+
+ while (n--)
+ {
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ *(float *) dst = 1.0;
+ dst += 4;
+ src += 4;
+ }
+ return samples;
+}
+
+#define conv_gF_rgbAF conv_gF_rgbaF
+
static long
conv_rgbF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
babl_component ("Ba"),
babl_component ("A"),
NULL);
+ const Babl *rgbAD = babl_format_new (
+ babl_model ("RaGaBaA"),
+ babl_type ("double"),
+ babl_component ("Ra"),
+ babl_component ("Ga"),
+ babl_component ("Ba"),
+ babl_component ("A"),
+ NULL);
+
const Babl *rgbA16 = babl_format_new (
babl_model ("RaGaBaA"),
babl_type ("u16"),
o (rgbaF, rgbaD);
o (rgbaD, rgbaF);
+ o (rgbAF, rgbAD);
+ o (rgbAD, rgbAF);
o (rgbaF, rgba8);
o (rgba8, rgbaF);
o (rgbaF, rgba16);
o (gaF, ga8);
o (gAF, gA8);
o (gF, g8);
+ o (gF, rgbAF);
+ o (gF, rgbaF);
o (ga8, gaF);
o (gA8, gAF);
o (g8, gF);
return samples;
}
+static long
+conv_gF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
+{
+ long n = samples;
+
+ while (n--)
+ {
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ *(float *) dst = 1.0;
+ dst += 4;
+ src += 4;
+ }
+ return samples;
+}
+
+#define conv_gF_rgbAF conv_gF_rgbaF
+
/*
static long
conv_rgb8_rgbaF (unsigned char *src,
o (gF, gaF);
o (gF, gAF);
o (gF, rgbF);
+ o (gF, rgbaF);
+ o (gF, rgbAF);
o (gaF, rgbaF);
o (gAF, rgbAF);
o (rgbaF, rgb8);
return samples;
}
+static INLINE long
+conv_ga8_gamma_2_2_rgba8_gamma_2_2 (unsigned char *src,
+ unsigned char *dst,
+ long samples)
+{
+ long n = samples;
+
+ while (n--)
+ {
+ *dst++ = *src;
+ *dst++ = *src;
+ *dst++ = *src++;
+ *dst++ = *src++;
+ }
+
+ return samples;
+}
+
static INLINE long
conv_ga8_linear_rgbaF_linear (unsigned char *src,
unsigned char *dst,
o (ga8_linear, rgbaF_linear);
o (ga8_gamma_2_2, rgbaF_linear);
+ o (ga8_gamma_2_2, rgba8_gamma_2_2);
+
o (g8_linear, gF_linear);
o (g8_gamma_2_2, gF_linear);
o (g8_linear, rgbaF_linear);
int init (void);
+
static inline long
-float_to_u8 (unsigned char *src_char, unsigned char *dst, long samples)
+float_to_u8_x1 (unsigned char *src_char, unsigned char *dst, long samples)
{
float *src = (float *)src_char;
long n = samples;
while (n--)
{
float r = src[0];
- float g = src[1];
- float b = src[2];
- float a = src[3];
-
dst[0] = (r >= 1.0f) ? 0xFF : ((r <= 0.0f) ? 0x0 : 0xFF * r + 0.5f);
- dst[1] = (g >= 1.0f) ? 0xFF : ((g <= 0.0f) ? 0x0 : 0xFF * g + 0.5f);
- dst[2] = (b >= 1.0f) ? 0xFF : ((b <= 0.0f) ? 0x0 : 0xFF * b + 0.5f);
- dst[3] = (a >= 1.0f) ? 0xFF : ((a <= 0.0f) ? 0x0 : 0xFF * a + 0.5f);
-
- dst += 4;
- src += 4;
+ dst += 1;
+ src += 1;
}
return samples;
}
+static inline long
+float_to_u8_x4 (unsigned char *src_char, unsigned char *dst, long samples)
+{
+ return float_to_u8_x1 (src_char, dst, samples * 4);
+}
+
+static inline long
+float_to_u8_x3 (unsigned char *src_char, unsigned char *dst, long samples)
+{
+ return float_to_u8_x1 (src_char, dst, samples * 3);
+}
+
+static inline long
+float_to_u8_x2 (unsigned char *src_char, unsigned char *dst, long samples)
+{
+ return float_to_u8_x1 (src_char, dst, samples * 2);
+}
+
+
+
static inline long
float_pre_to_u8_pre (unsigned char *src_char, unsigned char *dst, long samples)
{
}
static inline long
-float_to_u16 (unsigned char *src_char, unsigned char *dst_char, long samples)
+float_to_u16_x1 (unsigned char *src_char, unsigned char *dst_char, long samples)
{
float *src = (float *)src_char;
uint16_t *dst = (uint16_t *)dst_char;
long n = samples;
+ while (n--)
+ {
+ float r = src[0];
+ dst[0] = (r >= 1.0f) ? 0xFFFF : ((r <= 0.0f) ? 0x0 : 0xFFFF * r + 0.5f);
+ dst += 1;
+ src += 1;
+ }
+ return samples;
+}
+static inline long
+float_to_u16_x2 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ return float_to_u16_x1 (src_char, dst_char, samples * 2);
+}
+static inline long
+float_to_u16_x3 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ return float_to_u16_x1 (src_char, dst_char, samples * 3);
+}
+static inline long
+float_to_u16_x4 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ return float_to_u16_x1 (src_char, dst_char, samples * 4);
+}
+
+static inline long
+float_pre_to_u16_pre (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ float *src = (float *)src_char;
+ uint16_t *dst = (uint16_t *)dst_char;
+ long n = samples;
while (n--)
{
float r = src[0];
float g = src[1];
float b = src[2];
float a = src[3];
-
+
+ if (a > 1.0f) {
+ r /= a;
+ g /= a;
+ b /= a;
+ a /= a;
+ }
+
dst[0] = (r >= 1.0f) ? 0xFFFF : ((r <= 0.0f) ? 0x0 : 0xFFFF * r + 0.5f);
dst[1] = (g >= 1.0f) ? 0xFFFF : ((g <= 0.0f) ? 0x0 : 0xFFFF * g + 0.5f);
dst[2] = (b >= 1.0f) ? 0xFFFF : ((b <= 0.0f) ? 0x0 : 0xFFFF * b + 0.5f);
}
static inline long
-float_pre_to_u16_pre (unsigned char *src_char, unsigned char *dst_char, long samples)
+float_pre_to_u32_pre (unsigned char *src_char, unsigned char *dst_char, long samples)
{
float *src = (float *)src_char;
- uint16_t *dst = (uint16_t *)dst_char;
+ uint32_t *dst = (uint32_t *)dst_char;
long n = samples;
while (n--)
{
a /= a;
}
- dst[0] = (r >= 1.0f) ? 0xFFFF : ((r <= 0.0f) ? 0x0 : 0xFFFF * r + 0.5f);
- dst[1] = (g >= 1.0f) ? 0xFFFF : ((g <= 0.0f) ? 0x0 : 0xFFFF * g + 0.5f);
- dst[2] = (b >= 1.0f) ? 0xFFFF : ((b <= 0.0f) ? 0x0 : 0xFFFF * b + 0.5f);
- dst[3] = (a >= 1.0f) ? 0xFFFF : ((a <= 0.0f) ? 0x0 : 0xFFFF * a + 0.5f);
+ dst[0] = (r >= 1.0f) ? 0xFFFFFFFF : ((r <= 0.0f) ? 0x0 : 0xFFFFFFFF * r + 0.5f);
+ dst[1] = (g >= 1.0f) ? 0xFFFFFFFF : ((g <= 0.0f) ? 0x0 : 0xFFFFFFFF * g + 0.5f);
+ dst[2] = (b >= 1.0f) ? 0xFFFFFFFF : ((b <= 0.0f) ? 0x0 : 0xFFFFFFFF * b + 0.5f);
+ dst[3] = (a >= 1.0f) ? 0xFFFFFFFF : ((a <= 0.0f) ? 0x0 : 0xFFFFFFFF * a + 0.5f);
dst += 4;
src += 4;
return samples;
}
+
+static inline long
+float_to_u32_x1 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ float *src = (float *)src_char;
+ uint32_t *dst = (uint32_t *)dst_char;
+ long n = samples;
+ while (n--)
+ {
+ float r = src[0];
+
+ dst[0] = (r >= 1.0f) ? 0xFFFFFFFF : ((r <= 0.0f) ? 0x0 : 0xFFFFFFFF * r + 0.5f);
+
+ dst += 1;
+ src += 1;
+ }
+ return samples;
+}
+static inline long
+float_to_u32_x2 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ return float_to_u32_x1 (src_char, dst_char, samples * 2);
+}
+static inline long
+float_to_u32_x3 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ return float_to_u32_x1 (src_char, dst_char, samples * 3);
+}
+static inline long
+float_to_u32_x4 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ return float_to_u32_x1 (src_char, dst_char, samples * 4);
+}
+
+
+static inline long
+u32_to_float (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ uint32_t *src = (uint32_t *)src_char;
+ float *dst = (float *)dst_char;
+ long n = samples;
+ while (n--)
+ {
+ dst[0] = src[0] / 4294967295.0f;
+ dst ++;
+ src ++;
+ }
+ return samples;
+}
+
+static inline long
+u32_to_float_x4 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ u32_to_float (src_char, dst_char, samples * 4);
+ return samples;
+}
+
+static inline long
+u32_to_float_x3 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ u32_to_float (src_char, dst_char, samples * 3);
+ return samples;
+}
+
+
+static inline long
+u32_to_float_x2 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ u32_to_float (src_char, dst_char, samples * 2);
+ return samples;
+}
+
+
+static inline long
+u16_to_float (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ uint16_t *src = (uint16_t *)src_char;
+ float *dst = (float *)dst_char;
+ long n = samples;
+ while (n--)
+ {
+ dst[0] = src[0] / 65535.0f;
+ dst ++;
+ src ++;
+ }
+ return samples;
+}
+
+static inline long
+u16_to_float_x4 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ u16_to_float (src_char, dst_char, samples * 4);
+ return samples;
+}
+
+static inline long
+u16_to_float_x3 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ u16_to_float (src_char, dst_char, samples * 3);
+ return samples;
+}
+
+
+static inline long
+u16_to_float_x2 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ u16_to_float (src_char, dst_char, samples * 2);
+ return samples;
+}
+
+static inline long
+yau16_rgbaf (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ uint16_t *src = (uint16_t *)src_char;
+ float *dst = (float *)dst_char;
+ long n = samples;
+ while (n--)
+ {
+ dst[0] = src[0] / 65535.0f;
+ dst[1] = src[0] / 65535.0f;
+ dst[2] = src[0] / 65535.0f;
+ dst[3] = src[1] / 65535.0f;
+ dst +=4;
+ src +=2;
+ }
+ return samples;
+}
+
+
int
init (void)
{
babl_conversion_new (babl_format ("R'G'B'A float"),
babl_format ("R'G'B'A u8"),
"linear",
- float_to_u8,
+ float_to_u8_x4,
NULL);
babl_conversion_new (babl_format ("RGBA float"),
babl_format ("RGBA u8"),
"linear",
- float_to_u8,
+ float_to_u8_x4,
+ NULL);
+ babl_conversion_new (babl_format ("R'G'B' float"),
+ babl_format ("R'G'B' u8"),
+ "linear",
+ float_to_u8_x3,
+ NULL);
+ babl_conversion_new (babl_format ("RGB float"),
+ babl_format ("RGB u8"),
+ "linear",
+ float_to_u8_x3,
+ NULL);
+ babl_conversion_new (babl_format ("Y'A float"),
+ babl_format ("Y'A u8"),
+ "linear",
+ float_to_u8_x2,
+ NULL);
+ babl_conversion_new (babl_format ("YA float"),
+ babl_format ("YA u8"),
+ "linear",
+ float_to_u8_x2,
+ NULL);
+ babl_conversion_new (babl_format ("YA float"),
+ babl_format ("YA u8"),
+ "linear",
+ float_to_u8_x2,
+ NULL);
+ babl_conversion_new (babl_format ("Y' float"),
+ babl_format ("Y' u8"),
+ "linear",
+ float_to_u8_x1,
NULL);
babl_conversion_new (babl_format ("R'aG'aB'aA float"),
babl_format ("R'aG'aB'aA u8"),
babl_conversion_new (babl_format ("R'G'B'A float"),
babl_format ("R'G'B'A u16"),
"linear",
- float_to_u16,
+ float_to_u16_x4,
NULL);
babl_conversion_new (babl_format ("RGBA float"),
babl_format ("RGBA u16"),
"linear",
- float_to_u16,
+ float_to_u16_x4,
+ NULL);
+
+ babl_conversion_new (babl_format ("R'G'B' float"),
+ babl_format ("R'G'B' u16"),
+ "linear",
+ float_to_u16_x3,
+ NULL);
+ babl_conversion_new (babl_format ("RGB float"),
+ babl_format ("RGB u16"),
+ "linear",
+ float_to_u16_x3,
+ NULL);
+ babl_conversion_new (babl_format ("Y'A float"),
+ babl_format ("Y'A u16"),
+ "linear",
+ float_to_u16_x2,
+ NULL);
+ babl_conversion_new (babl_format ("YA float"),
+ babl_format ("YA u16"),
+ "linear",
+ float_to_u16_x2,
+ NULL);
+ babl_conversion_new (babl_format ("Y' float"),
+ babl_format ("Y' u16"),
+ "linear",
+ float_to_u16_x1,
+ NULL);
+ babl_conversion_new (babl_format ("Y float"),
+ babl_format ("Y u16"),
+ "linear",
+ float_to_u16_x1,
NULL);
babl_conversion_new (babl_format ("R'aG'aB'aA float"),
babl_format ("R'aG'aB'aA u16"),
float_pre_to_u16_pre,
NULL);
+
+ /* float and u32 */
+ babl_conversion_new (babl_format ("R'G'B'A float"),
+ babl_format ("R'G'B'A u32"),
+ "linear",
+ float_to_u32_x4,
+ NULL);
+ babl_conversion_new (babl_format ("RGBA float"),
+ babl_format ("RGBA u32"),
+ "linear",
+ float_to_u32_x4,
+ NULL);
+ babl_conversion_new (babl_format ("R'G'B' float"),
+ babl_format ("R'G'B' u32"),
+ "linear",
+ float_to_u32_x3,
+ NULL);
+ babl_conversion_new (babl_format ("RGB float"),
+ babl_format ("RGB u32"),
+ "linear",
+ float_to_u32_x3,
+ NULL);
+ babl_conversion_new (babl_format ("Y'A float"),
+ babl_format ("Y'A u32"),
+ "linear",
+ float_to_u32_x2,
+ NULL);
+ babl_conversion_new (babl_format ("YA float"),
+ babl_format ("YA u32"),
+ "linear",
+ float_to_u32_x2,
+ NULL);
+ babl_conversion_new (babl_format ("Y' float"),
+ babl_format ("Y' u32"),
+ "linear",
+ float_to_u32_x1,
+ NULL);
+ babl_conversion_new (babl_format ("Y float"),
+ babl_format ("Y u32"),
+ "linear",
+ float_to_u32_x1,
+ NULL);
+ babl_conversion_new (babl_format ("R'aG'aB'aA float"),
+ babl_format ("R'aG'aB'aA u32"),
+ "linear",
+ float_pre_to_u32_pre,
+ NULL);
+ babl_conversion_new (babl_format ("RaGaBaA float"),
+ babl_format ("RaGaBaA u32"),
+ "linear",
+ float_pre_to_u32_pre,
+ NULL);
+ babl_conversion_new (babl_format ("YA u32"),
+ babl_format ("YA float"),
+ "linear",
+ u32_to_float_x2,
+ NULL);
+ babl_conversion_new (babl_format ("Y'A u32"),
+ babl_format ("Y'A float"),
+ "linear",
+ u32_to_float_x2,
+ NULL);
+ babl_conversion_new (babl_format ("Y u32"),
+ babl_format ("Y float"),
+ "linear",
+ u32_to_float,
+ NULL);
+ babl_conversion_new (babl_format ("Y' u32"),
+ babl_format ("Y' float"),
+ "linear",
+ u32_to_float,
+ NULL);
+ babl_conversion_new (babl_format ("RGBA u32"),
+ babl_format ("RGBA float"),
+ "linear",
+ u32_to_float_x4,
+ NULL);
+ babl_conversion_new (babl_format ("R'G'B'A u32"),
+ babl_format ("R'G'B'A float"),
+ "linear",
+ u32_to_float_x4,
+ NULL);
+
+ babl_conversion_new (babl_format ("RGB u32"),
+ babl_format ("RGB float"),
+ "linear",
+ u32_to_float_x3,
+ NULL);
+ babl_conversion_new (babl_format ("R'G'B' u32"),
+ babl_format ("R'G'B' float"),
+ "linear",
+ u32_to_float_x3,
+ NULL);
+
+
+
+ babl_conversion_new (babl_format ("YA u16"),
+ babl_format ("YA float"),
+ "linear",
+ u16_to_float_x2,
+ NULL);
+ babl_conversion_new (babl_format ("Y'A u16"),
+ babl_format ("Y'A float"),
+ "linear",
+ u16_to_float_x2,
+ NULL);
+ babl_conversion_new (babl_format ("Y u16"),
+ babl_format ("Y float"),
+ "linear",
+ u16_to_float,
+ NULL);
+ babl_conversion_new (babl_format ("Y' u16"),
+ babl_format ("Y' float"),
+ "linear",
+ u16_to_float,
+ NULL);
+ babl_conversion_new (babl_format ("RGBA u16"),
+ babl_format ("RGBA float"),
+ "linear",
+ u16_to_float_x4,
+ NULL);
+ babl_conversion_new (babl_format ("R'G'B'A u16"),
+ babl_format ("R'G'B'A float"),
+ "linear",
+ u16_to_float_x4,
+ NULL);
+
+ babl_conversion_new (babl_format ("RGB u16"),
+ babl_format ("RGB float"),
+ "linear",
+ u16_to_float_x3,
+ NULL);
+ babl_conversion_new (babl_format ("R'G'B' u16"),
+ babl_format ("R'G'B' float"),
+ "linear",
+ u16_to_float_x3,
+ NULL);
+ babl_conversion_new (babl_format ("Y'A u16"),
+ babl_format ("R'G'B'A float"),
+ "linear",
+ yau16_rgbaf,
+ NULL);
return 0;
}
}
#define GAMMA_RGBA(func, munge) \
-static long \
+static inline long \
func (const float *src, float *dst, long samples)\
{\
int i = samples;\
GAMMA_RGBA(conv_rgbaF_linear_rgbaF_gamma, linear_to_gamma_2_2_sse2)
GAMMA_RGBA(conv_rgbaF_gamma_rgbaF_linear, gamma_2_2_to_linear_sse2)
+static long conv_rgbaF_linear_rgbAF_gamma (const float *src, float *dst, long samples)
+{
+ float *tmp = alloca (sizeof(float)*4*samples);
+ conv_rgbaF_linear_rgbaF_gamma (src, tmp, samples);
+ conv_rgbaF_linear_rgbAF_linear (tmp, dst, samples);
+ return samples;
+}
+
#define YA_APPLY(load, store, convert) \
{ \
__v4sf yyaa0, yyaa1; \
conv_rgbaF_linear_rgbAF_linear,
NULL);
+ babl_conversion_new(rgbaF_linear,
+ rgbAF_gamma,
+ "linear",
+ conv_rgbaF_linear_rgbAF_gamma,
+ NULL);
+
/* Which of these is faster varies by CPU, and the difference
* is big enough that it's worthwhile to include both and
* let them fight it out in the babl benchmarks.
return conv_yF_y8 (src, dst, samples * 4) / 4;
}
+static long
+conv_rgbAF_rgbA8 (const float *src, uint8_t *dst, long samples)
+{
+ return conv_yF_y8 (src, dst, samples * 4) / 4;
+}
+
#endif
int init (void);
init (void)
{
#if defined(USE_SSE2)
+
+ const Babl *rgbAF_linear = babl_format_new (
+ babl_model ("RaGaBaA"),
+ babl_type ("float"),
+ babl_component ("Ra"),
+ babl_component ("Ga"),
+ babl_component ("Ba"),
+ babl_component ("A"),
+ NULL);
+ const Babl *rgbA8_linear = babl_format_new (
+ babl_model ("RaGaBaA"),
+ babl_type ("u8"),
+ babl_component ("Ra"),
+ babl_component ("Ga"),
+ babl_component ("Ba"),
+ babl_component ("A"),
+ NULL);
+ const Babl *rgbAF_gamma = babl_format_new (
+ babl_model ("R'aG'aB'aA"),
+ babl_type ("float"),
+ babl_component ("R'a"),
+ babl_component ("G'a"),
+ babl_component ("B'a"),
+ babl_component ("A"),
+ NULL);
+ const Babl *rgbA8_gamma = babl_format_new (
+ babl_model ("R'aG'aB'aA"),
+ babl_type ("u8"),
+ babl_component ("R'a"),
+ babl_component ("G'a"),
+ babl_component ("B'a"),
+ babl_component ("A"),
+ NULL);
+
const Babl *rgbaF_linear = babl_format_new (
babl_model ("RGBA"),
babl_type ("float"),
if ((babl_cpu_accel_get_support () & BABL_CPU_ACCEL_X86_SSE2))
{
CONV(rgbaF, rgba8);
+ CONV(rgbAF, rgbA8);
CONV(rgbF, rgb8);
CONV(yaF, ya8);
CONV(yF, y8);
#include <stdio.h>
#include <stdlib.h>
-#include "babl/babl.h"
+#include "../config.h"
+#include "babl/babl-internal.h"
int main (int argc, char **argv)
{
- if (argc != 3)
+ int final = 0;
+ const Babl *fish;
+ if (argc < 3)
{
fprintf (stderr, "need two args, from and to babl-formats\n");
return -1;
}
+ if (argc == 4)
+ final = 1;
+
+ if (!final)
+ {
putenv ("BABL_DEBUG_CONVERSIONS" "=" "1");
putenv ("BABL_TOLERANCE" "=" "100000.0");
+ }
+
babl_init ();
- babl_fish (babl_format(argv[1]), babl_format (argv[2]));
+
+ fish = babl_fish (babl_format(argv[1]), babl_format (argv[2]));
+ if (!fish)
+ return -1;
+
+ if (final)
+ switch (fish->class_type)
+ {
+ case BABL_FISH:
+ fprintf (stderr, "%s\n", babl_get_name (fish));
+ break;
+ case BABL_FISH_PATH:
+ fprintf (stderr, "chosen %s to %s: steps: %i error: %f cost: %f\n", argv[1], argv[2], fish->fish_path.conversion_list->count, fish->fish.error, fish->fish_path.cost);
+ for (int i = 0; i < fish->fish_path.conversion_list->count; i++)
+ {
+ fprintf (stderr, "\t%s\n",
+ babl_get_name(fish->fish_path.conversion_list->items[i] ));
+ }
+ break;
+ }
+
+
babl_exit ();
return 0;